package com.gitee.qdbp.jdbc.support;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import com.gitee.qdbp.jdbc.plugins.DbPluginContainer;

/**
 * 从spring容器中扫描插件
 *
 * @author zhaohuihua
 * @version 20210704
 */
public class DbPluginScanner implements InitializingBean, ApplicationContextAware {

    /** 数据库插件容器类 **/
    private DbPluginContainer pluginContainer;
    private ApplicationContext context;

    @Override
    public void afterPropertiesSet() {
        // 从spring容器中扫描插件
        scanAndRegisterPlugin();
    }

    protected void scanAndRegisterPlugin() {
        PluginInstanceScanTools.scanAndRegisterWhereSqlBuilder(pluginContainer, context);
        PluginInstanceScanTools.scanAndRegisterUpdateSqlBuilder(pluginContainer, context);
        PluginInstanceScanTools.scanAndRegisterOrderBySqlBuilder(pluginContainer, context);
        PluginInstanceScanTools.scanAndRegisterBatchInsertExecutor(pluginContainer, context);
        PluginInstanceScanTools.scanAndRegisterBatchUpdateExecutor(pluginContainer, context);
    }

    /** 数据库插件容器类 **/
    public void setPluginContainer(DbPluginContainer pluginContainer) {
        this.pluginContainer = pluginContainer;
    }

    @Override
    public void setApplicationContext(ApplicationContext context) {
        this.context = context;
    }
}
